package com.personalkeeper;

import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.RadialGradient;
import android.location.Location;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;
import com.personalkeeper.PersonalKeeper.Utils;

public class CircleOverlay extends Overlay {
    Location location;
    public CircleOverlay(Location location) {
        this.location = location;
    }
    public void setLocation(Location location) {
        this.location = location;
    }
    public Location getLocation() {
        return this.location;
    }
    @Override
    public void draw(Canvas canvas, MapView mapView, boolean shadow) {
        if (location != null) {
            Projection projection = mapView.getProjection();
            int radius = (int)projection.metersToEquatorPixels(location.getAccuracy());
            Paint paint = new Paint();
            paint.setAlpha(50);

            paint.setStyle(Paint.Style.FILL);
            paint.setDither(true);

            Point center = new Point();

            GeoPoint centerPont = Utils.geoPointFromLocation(location);
            projection.toPixels(centerPont, center);
            RadialGradient gradient = new RadialGradient(center.x - radius, center.y - radius, 200, Color.CYAN,
                    Color.LTGRAY, android.graphics.Shader.TileMode.CLAMP);
            paint.setShader(gradient);
            canvas.drawCircle((float)center.x, (float)center.y, radius, paint);
        }
        super.draw(canvas, mapView, shadow);
    }
}
